﻿#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#include "RBTree.h"

//测试红黑树
//int main() {
//	//int a[] = { 16, 3, 7, 11, 9, 26, 18, 14, 15 };
//	int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };//涉及双旋
//	RBTree<int, int> t;
//	for (auto e : a)
//		t.Insert(make_pair(e, e));
//	t.InOrder();
//	cout << t.IsBalance() << endl;
//	return 0;
//}


//进一步测试红黑树
//int main() {
//	const int N = 1000000;
//	vector<int> v;
//	v.reserve(N);
//	srand((unsigned int)time(0));
//
//	for (size_t i = 0; i < N; i++)
//		v.push_back(rand() + i);
//	
//	size_t begin2 = clock();
//	RBTree<int, int> t;
//	for (auto e : v) 
//		t.Insert(make_pair(e, e));
//	size_t end2 = clock();
//
//	size_t begin1 = clock();
//	for (auto e : v)
//		t.Find(e);
//	size_t end1 = clock();
//
//	cout << "是否为红黑树：" << t.IsBalance() << endl;
//	//cout << "Insert:" << end1 - begin1 << endl;
//	cout << "Height:" << t.Height() << endl;
//	cout << "Size:" << t.Size() << endl;
//	cout << "Find Time:" << end1 - begin1 << endl;
//	cout << "Insert Time:" << end2 - begin2 << endl;
//	return 0;
//}



#include "MySet.h"
#include "MyMap.h"

void test_set() {
	bit::set<int> s;
	s.Insert(4);
	s.Insert(1);
	s.Insert(2);
	s.Insert(3);
	s.Insert(2);
	s.Insert(0);
	s.Insert(10);
	s.Insert(5);
	bit::set<int>::iterator it = s.begin();
	while (it != s.end()) {
		cout << *it << " ";
		++it;
	}
	cout << endl;
	for (auto e : s)
		cout << e << " ";
	cout << endl;
}

void test_map() {
	bit::map<string, string> dict;
	dict.Insert(make_pair("sort", "排序"));
	dict.Insert(make_pair("sort", "xx"));
	dict.Insert(make_pair("left", "左边"));
	dict.Insert(make_pair("right", "右边"));
	bit::map<string, string>::iterator it = dict.begin();
	while (it != dict.end()) {
		//it->first += "y";
		it->second += "y";
		cout << it->first << ":" << it->second << endl;
		++it;
	}

	string arr[] = { "苹果", "西瓜", "苹果", "西瓜", "苹果", "苹果", "西瓜", "苹果", "香蕉", "苹果", "香蕉" };
	bit::map<string, int> countMap;
	for (auto& e : arr)
		countMap[e]++;

	for (auto& kv : countMap)
		cout << kv.first << ":" << kv.second << endl;
}
int main() {
	//test_set();
	test_map();
	return 0;
}